package com.orcamento.entity.report.subreport;

import java.util.List;

import com.orcamento.entity.Gain;
import com.orcamento.entity.enums.Month;
import com.orcamento.util.Money;

public class MonthGain implements Comparable<MonthGain> {

	private Month month;
	private Integer year;
	private Money total = new Money();

	public MonthGain(Integer month, Integer year, List<Gain> gains) {
		this.month = Month.findById(month);
		this.year = year;
		setTotalMonthGain(gains);
	}
	
	public Month getMonth() {
		return month;
	}

	public Integer getYear() {
		return year;
	}

	public Money getTotal() {
		return total;
	}

	private void setTotalMonthGain(List<Gain> gains) {
		for( Gain gain : gains ) {
			total = total.plus( gain.getValue() );
		}
	}

	@Override
	public int compareTo(MonthGain other) {
		if(other == null) {
			return 1;
		}
		if(total.equals(other.total)) {
			return 0;
		}
		return total.greaterThan(other.total) ? 1 : -1 ;
	}

}
